package com.ruoyi.business.component.mqconsumer.repaymentconsumers;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.bizsys.domain.ExtMonnifyOrder;
import com.ruoyi.bizsys.service.ICreditAccountService;
import com.ruoyi.bizsys.service.IExtMonnifyOrderService;
import com.ruoyi.bizsys.service.ILoanOverflowService;
import com.ruoyi.bizsys.utils.BizConstants;
import com.ruoyi.business.service.IMonnifyRepaymentService;
import com.ruoyi.common.core.redis.RedisCache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * MONNIFY的处理类
 *
 * @author wqg
 * @description
 * @date 2022/5/21
 */
@Slf4j
@Service(BizConstants.ROCKMQ_REPAYMENT_TYPE_MONNIFY)
public class MonnifyWebhookConsumer implements IRepaymentMqService {

    @Autowired
    IMonnifyRepaymentService monnifyRepaymentService;

    @Autowired
    RedisCache redisCache;
    @Autowired
    private IExtMonnifyOrderService iExtMonnifyOrderService;
    @Autowired
    ILoanOverflowService iLoanOverflowService;
    @Autowired
    ICreditAccountService creditAccountService;

    /**
     * @param msgObj
     */
    @Override
    public void handle(JSONObject msgObj) {
        log.info("MonnifyConsumer start >>> data = {}", msgObj.toString());

        ExtMonnifyOrder extMonnifyOrder = msgObj.getObject("extMonnifyOrder", ExtMonnifyOrder.class);
        String custNo = msgObj.getString("custNo");

        extMonnifyOrder = iExtMonnifyOrderService.selectExtMonnifyOrderById(extMonnifyOrder.getId());
        if (null != extMonnifyOrder.getStatus() && extMonnifyOrder.getStatus() == 1) {
            log.info("extMonnifyOrder.status = 1");
            return;
        }

        monnifyRepaymentService.repaymentLock(extMonnifyOrder);

        //删除redis
        redisCache.deleteObject(BizConstants.TRANSFER_TO_US_THREAD + custNo);

        log.info("MonnifyConsumer end >>> data = {}", msgObj);
    }
}
